<?php
    include 'admin_logueado.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<?php
function generarID()
{

     include_once 'conectar_bd.php';
    $base= conectar_lectura_escritura();
     
      $query1 = "SELECT MAX(id_usuario) FROM usuarios";
      $results1 = $base->query($query1);
      $arr1 = $results1->fetchArray();
     
      if( $arr1>0)
         //HABIA AL MENOS UN USUARIO
        $ultimo_id = $arr1['MAX(id_usuario)'];
      else $ultimo_id=0;//para que empiece desde 1
      
      
    $query2 = "INSERT OR REPLACE INTO usuarios (id_usuario) VALUES ($ultimo_id+1)";
     $results2 = $base->exec($query2);

      if(!$results2)
                {
                    echo "<i>'usuarios'</i> not updated.";
                    exit(0);
                }
      return $ultimo_id+1;
      
}

    if (!isset($_COOKIE['usuario']))
    {
        $id_nuevo= generarID();
        setcookie('usuario',$id_nuevo ,time()+3600);
      
    }
 
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<title>E.M inmobiliaria</title>
		
		<link rel="shortcut icon" href="img/favicon.ico" type="image/x-ico"/>
		
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
		
		<link href="librerias/css/bootstrap.min.css" rel="stylesheet" media="screen"/>
		<link rel="stylesheet" type="text/css" href="css/ajustes.css" />
		<link rel="stylesheet" type="text/css" href="css/ajustes_index.css" />
		<link rel="stylesheet" type="text/css" href="css/cambiando_estilo.css" />
		
		
		 <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
		 <link rel="stylesheet" href="/resources/demos/style.css" />
		 
		 <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
		 <script src="librerias/js/bootstrap.min.js" type="text/javascript"></script>
		 <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js" type="text/javascript"></script>
		 
                 <!-- script src="librerias/js/sha1.js" type="text/javascript"></script -->
	
		<script src="js/loadXML.js" type="text/javascript"></script>
		<script src="js/script_index_php_1.js" type="text/javascript"></script>
		<script src="js/chequear_estilo.js" type="text/javascript"></script>
		
		<link rel="stylesheet" type="text/css" href="css/estilo1.css" id="css_que_cambia"/>
	</head>

	<body id="body_index">
		<!-- Menú superior -->
		<!--=========== BOTONES DE CAMBIO DE ESTILO ================-->
                <div class="row-fluid">
                    <div class="span12">
                        <?php 
                                if(admin_logueado()){
                                   $url_actual = $_SERVER['REQUEST_URI'];
                                   echo "<div id='link_logout'><a href='logout.php?url=$url_actual'>logout</a></div>";
                                }
                            ?>
                        <!--form-->
                        <div id="radio">
                            <input type="radio" id="radio1" name="radio" onclick="cambiarCss1()"/>
                            <label for="radio1" id="label1">Style 1</label>
                            <input type="radio" id="radio2" name="radio" onclick="cambiarCss2()"/>
                            <label for="radio2" id="label2">Style 2</label>
                        </div>
                        <!--/form-->
                            
                    </div>
                </div>
		<!--=========== ENCABEZADO ================-->
		<div class="container">
		<div class="row-fluid" id="encabezado_">
		
			<div class="span12 barra_s" id="barra_bot_log">
				<!-- logo-->
				<div class="span4 well logo_s">
					<img id="logo_img" alt="logo" src="img/LOGO1ELI.png" />
				</div>
				<!-- botones -->
				<div class="span8 well botones_s">
					<ul class="lista_botones">
						<li class="boton_l"><a href="autores.php" class="links" >Autores</a></li>
						<li class="boton_l" id="boton_readme"><a href="readme.php" class="links">Readme</a></li>
						
					</ul>
				</div>
				
			</div>
		</div>
		
		<div class="row-fluid">
			<div class="span12">
				<ul class="breadcrumb">
					<li class="active link_barra"><span class="breadcrumb_actual">Home</span></li>
				</ul>
			</div>
		</div>	
		<!--=========== CUERPO ================-->
		<div class="row-fluid">
			
		
			
			<div class="span12 ppal">
								
				<!-- izq -->
                                <div class="span3">
                                    <div class=" well izq">
					<ul class="nav nav-list">
						    <li class="nav-header title_list"><h5 class="titulo_panel">Menu</h5></li>
						    <li><a class="item_menu" href="propiedades.php">Propiedades</a></li>
						    <li>
								<div id="contacto">
								<p>
								CONTACTO:<br/>
								e.m.inmobiliaria@gmail.com<br/>
								T.E: 0291-4538869<br/>
								</p>
								</div>
							</li>
					    </ul>
                                      
                                    </div>
                                    
                                    <div class=" well izq logueo_admin">   
                                        
                                        <?php 
                                        if(!admin_logueado()){
                                            echo "<div id='login_admin'> <table id='tabla_logueo'> <tr> <td> User: </td> <td >    <input type='text' id='usuario' class='logueo_admin_input'></input> </td></tr> <tr> <td> Password: </td><td ><input  type='password' name='password' id='password' class='logueo_admin_input'></input></td></tr> <tr id='boton_logueo'> <td> <button class='boton_login' onclick='login()' type='button'>Login</button> </td></tr> </table> </div>";
                                        }else{
                                            echo "<ul class='nav nav-list'><li class='fila_logueo'> <a class='item_menu' href='admin.php'>Admin</a> </li></ul>";
                                            //echo "<li class='fila_logueo'><a class='item_menu' href='logout.php?url=index.php'><h5>Logout</h5></a> </li></ul>";
                                        }
                                        ?>
                                             
                                    </div>
                                 </div>
				<!-- centro -->
				<div class="span6 well medio">
                                    <?php
					
                                        echo '<div id="myCarousel" class="carousel slide">';
										  
                                        include_once 'conectar_bd.php';
                                        $base=  conectar_solo_lectura();

                                        $query = "SELECT * FROM destacados NATURAL JOIN propiedades";
                                        $results = $base->query($query);

                                        //CIRCULITOS--------------
                                        
                                                echo '<ol class="carousel-indicators" id="carousel_circulitos">';
                                                                                                                                              
                                                    $primer_item_circ = 1;
                                                    $contador=1;
                                                
                                                     while($arr_circ = $results->fetchArray())
                                                    {
                                                        if(count($arr_circ) == 0) break;
                                                    
                                                        if($primer_item_circ==1){
                                                            echo "<li data-target='#myCarousel' data-slide-to='0' class='active'></li>"; 
                                                            $primer_item_circ=0;
                                                        }else{
                                                             echo "<li data-target='#myCarousel' data-slide-to='$contador'></li>";
                                                             $contador=$contador+1;
                                                         }
                                                
                                                    }
                                                    echo "</ol>";
                                          //---------------------------------      
                                          //IMAGENES-------------------------      
                                                 
                                                echo '<div class="carousel-inner" id="carousel_destacados">';
                                                
                                                $primer_item = 1;
                                                
                                                while($arr = $results->fetchArray())
                                                {
                                                  if(count($arr) == 0) break;
                                                      
                                                  $id_prop = $arr['id_propiedad'];
                                                  $comentario = $arr['comentario']; 
                                                  $source = $arr['img1_path'];
                                                  $img_alt = $arr['img1_alt'];
                                                //<!-- Carousel items -->
                                                    
                                                    if($primer_item==1){
                                                        echo "<div class='item active'><a href='propiedad.php?id_propiedad=$id_prop'><img class='foto_destacados' src='$source' alt='$img_alt'></img></a><div class='carousel-caption'><span class='titulo_comentario'>Propiedad $id_prop</span><span class='cont_comentario'>$comentario</span></div></div>";
                                                        $primer_item=0;
                                                    }else{
                                                        echo "<div class='item'><a href='propiedad.php?id_propiedad=$id_prop'><img class='foto_destacados' src='$source' alt='$img_alt'></img></a><div class='carousel-caption'><span class='titulo_comentario'>Propiedad $id_prop</span><span class='cont_comentario'>$comentario</span></div></div>";
                                                    }
                                                        
                                                } 
                                               
                                                ?>
                                              
					  </div>
					  <!-- Carousel nav -->
					
					
					</div>
					
					<div id="titulo_destacados" class="container">
						PROPIEDADES DESTACADAS						
					</div>

				</div>
				<!-- der -->
				<div class="span3 well der">
					<ul class="nav nav-list">
						    <li class="nav-header titulo_panel">Favoritos</li>
						    <li class="active">
						    	<div id="favorito1">
								</div>
						    		
						    </li>
					    </ul>
				</div>
			</div>
		</div>
		
		<!--=========== PIE================-->
		<div class="row-fluid">
			<div class="span12 well pie">
					<div class="span10" id="pie_imagen">
						
					</div>
					<div class="span2 ">
						&copy; IAW 2013
					</div>
					
				
			</div>
		</div>
	</div>
		
	</body>
</html>
